package sp.controller.filter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.beans.factory.annotation.Autowired;

import sp.service.UserService;
import sp.util.constant.SysConstant;

public class SysUserFilter extends PathMatchingFilter{

	@Autowired UserService userService;
	
	@Override
	protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue)
			throws Exception {
		System.out.println("系统过滤器");
		String typeCode = (String)SecurityUtils.getSubject().getPrincipal();
		request.setAttribute(SysConstant.USER, userService.findUserByName(typeCode));
		return true;
	}
}
